package com.Monica.pojo;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.junit.Test;

import java.util.List;

public class MyTest {
    @Test
    public void test() throws DocumentException {
        SAXReader reader = new SAXReader();
        Document doc = reader.read("src/books.xml");
        Element element = doc.getRootElement();
        List<Element> books = element.elements("book");
        for (Element book : books){
            String sn = book.attributeValue("sn");
            String name = book.elementText("name");
            String price = book.elementText("price");
            String author = book.elementText("author");
            System.out.println(new Book(sn,name,Double.parseDouble(price),author));
        }
    }
}
